/**
 * Title: HttpApiUtil.java
 * Description:
 * Copyright: Copyright (c) 2008
 * Company:深圳彩讯科技有限公司
 * Author 罗旭东 (hi@luoxudong.com)
 * Date 2013-8-20 下午3:04:01
 * Version 1.0
 */
package com.luoxudong.phonenumber.service.net.http.utils;

import android.content.Context;

import com.luoxudong.phonenumber.service.utils.MetaDataUtil;

/** 
 * ClassName: HttpApiUtil
 * Description:接口定义类
 * Create by 罗旭东
 * Date 2013-8-20 下午3:04:01
 */
public class HttpApiUtil {
	/**
	 * 访问来源 
	 */
	public static final int COMEFROM = 1;
	
	/**
	 * 分页获取请求数据的最大数
	 */
	public static final int REQUEST_PAGENUM = 20;
	
	public static final String URL_SERVICE_GET_ALL_AREAS = "/GetAreaInfo.ashx";
	public static final String URL_SERVICE_GET_PROVINCE = "/GetProvinceInfo.ashx";
	public static final String URL_SERVICE_GET_PRODUCT_DETAIL = "/GetProductDetail.ashx";
	
	/**
	 * 
	 * @description:获取服务器地址
	 * @return String 服务器地址
	 * @throws
	 */
	public static String getApiRootUrl(Context context) {
		if (MetaDataUtil.isRelease(context)) {
			return MetaDataUtil.getReleaseServer(context);
		} else {
			return MetaDataUtil.getDebugServer(context);
		}
	}
	
	/**
	 * 
	 * @description:获取完整url路径
	 * @param url 不带主域名的url
	 * @return String
	 * @throws
	 */
	public static String getFullUrl(Context context, String url)
	{
		String rootUrl = getApiRootUrl(context);
		String fullUrl = null;
		
		if (rootUrl == null || rootUrl == "/")
		{
			rootUrl = "";
		}
		
		if (url == null || url == "/")
		{
			url = "";
		}
		
		fullUrl = rootUrl + url;
		
		if (rootUrl.length() != 0 && url.length() != 0)
		{
			if (rootUrl.lastIndexOf("/") != rootUrl.length() - 1 && url.indexOf("/") != 0)
			{
				fullUrl = rootUrl + "/" + url;
			}
			else if (rootUrl.lastIndexOf("/") == rootUrl.length() - 1 && url.indexOf("/") == 0 && url.length() > 1)
			{
				fullUrl = rootUrl + url.substring(1);
			}
			
		}
		
		return fullUrl;
	}
}
